#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

wget 'https://github.com/koendv/openscad-raspberrypi/releases/download/v1.6/OpenSCAD-2021.03.26-armhf.AppImage' -O ~/OpenSCAD.AppImage || error "Failed to download appimage!"

chmod +x ~/OpenSCAD.AppImage || error "Failed to mark as executable!"

echo "[Desktop Entry]
Name=OpenSCAD
GenericName=The Programmers Solid 3D CAD Modeller
Comment=OpenSCAD is a software for creating 3D CAD objects.
Exec=bash -c 'sudo modprobe fuse; ~/OpenSCAD.AppImage'
Icon=$(dirname $0)/icon-64.png
Terminal=false
Type=Application
MimeType=application/x-openscad;
Categories=Graphics;3DGraphics;Engineering;
Keywords=3d;solid;geometry;csg;model;stl;
StartupNotify=true" > ~/.local/share/applications/OpenSCAD.desktop || error "Failed to create menu button!"
